"""
输入数字 n，按顺序打印出从 1 到最大的 n 位十进制数。比如输入 3，则打印出 1、2、3 一直到最大的 3 位数 999。
示例 1:
输入: n = 1
输出: [1,2,3,4,5,6,7,8,9]
说明：
    用返回一个整数列表来代替打印
    n 为正整数
链接：https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof
"""


class Solution:
    def printNumbers(self, n: int) -> [int]:
        def dfs(x):
            if x == n:
                temp = ''.join(num).lstrip('0')
                if temp != '':
                    res.append(int(temp))
                return
            for i in range(10):
                num[x] = str(i)
                dfs(x + 1)

        num = ['0'] * n
        res = []
        dfs(0)
        return res


class Solution1:
    def printNumbers(self, n: int) -> [int]:
        def dfs(x):
            if x == n:
                temp = ''.join(num).lstrip('0')
                if temp != '':
                    res.append(int(temp))
                return

            for i in range(10):
                num[x] = str(i)
                dfs(x + 1)


        num = ['0'] * n
        print(num)
        res = []
        dfs(0)
        return res


if __name__ == "__main__":
    A = Solution()
    print(A.printNumbers(3))
    A = Solution1()
    print(A.printNumbers(3))
